

/**
 * 是否合法IP地址
 * @param value
 * @param callback
 */
export function validateIP(rule, value, callback) {
  if (value !== '' && typeof value !== 'undefined' && value != null) {
    const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    if ((!reg.test(value)) && value !== '') {
      callback(new Error('请输入正确的IP地址'))
    } else {
      callback()
    }
  }else{
    callback()
  }
}

/**
 * 是否合法MAC地址
 * @param value
 * @param callback
 */
export function validateMAC(rule, value, callback) {
  if (value !== '' && typeof value !== 'undefined' && value != null) {
    const reg = /[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}/
    if ((!reg.test(value)) && value !== '') {
      callback(new Error('请输入正确的MAC地址'))
    } else {
      callback()
    }
  }else{
    callback()
  }
}
